﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace SchemaMonitor.json
{
    public class CPage : CDict
    {
        //Members
        public object[] Data;
        public CPaging  Paging;
        public CCursors Cursors {  get { return Paging?.Cursors; } }

        //Constructor
        public CPage(object obj) : this((Dictionary<string, object>)obj) { }
        public CPage(Dictionary<string, object> d) : base(d)
        {
            Data    = AsArr("data");
            Paging  = AsPaging("paging");
        }

        //Derived
        public bool HasData    { get { return null != Data && Data.Length > 0;    } }
        public bool HasPaging  { get { return null != Paging;  } }
        public bool HasCursors { get { return HasPaging && Paging.HasCursors; } }

        public string Summary
        {
            get
            {
                StringBuilder sb = new StringBuilder();
                if (!HasData)
                    sb.Append("no data");
                else
                    sb.Append(Data.Length);

                if (HasPaging)
                    sb.Append(Paging.Summary);
                return sb.ToString();
            }
        }
    }
}
